export default{
	v: 'test',
	envs: {
		'test':"http://39.105.116.130:8081",
		'my':'http://39.105.116.130/dev-api',
		'prd':'http://api.xsmnjd.com/prod-api',
		'testSocke': 'ws://rblt.qifudaren.net',
		'prdSocke': 'ws://http://39.105.116.130:8081'
	},
	getUrl: function () {
		return this.envs[this.v];
	},
	getSocketUrl: function () {
		return this.envs[this.v + 'Socke'];
	},
	isTest: function () {
		return this.v !== 'prd'
	},
	getUploadUrl: function () {
		return this.envs[this.v] + '/api/upload/image';
	},
	getUploadImageUrl: function () {
		return this.envs[this.v] + '/api/upload/image';
	},
	getUploadVideoUrl: function () {
		return this.envs[this.v] + '/api/upload/video';
	},
	getHeader: function () {
		const header = {}
		if(uni.getStorageSync("token")){
			header["Authorization"] = "Bear " + uni.getStorageSync("token")
		}
		return header;
	},
	getPostHeader: function () {
		const header = this.getHeader()
		header["Content-Type"] = "application/json;charset=UTF-8"
		return header
	},
	getGetHeader: function () {
		const header = this.getHeader()
		header["Content-Type"] = "application/x-www-form-urlencoded"
		return header
	},
	getRequestResult : function (resolve:any, reject:any, resonpes:any) {
		// 将结果抛出
		if(resonpes.data.status === 200){
			resolve(resonpes.data)
		}else if(resonpes.data.status === 401 || resonpes.data.status === 110002){
			uni.reLaunch({url:"/pages/login/login"})
			reject(resonpes.data)
		}else{
		    reject(resonpes.data)
			uni.hideLoading();
		}
	},
	getUploadResult : function ( resonpes:any, file:any) {
		if (resonpes.data.status == 200) {
			file.url = resonpes.data.data.url
			file.status = 'success'
		} else if(resonpes.data.status == 401){
			file.status = 'noPermission'
		}else {
			file.status = 'fail'
		}
		return file
	},
	getDownloadResult : function ( resonpes:any, file:any) {
		if (resonpes.data.status == 200) {
			file.url = resonpes.data.data.url
			file.status = 'success'
		} else if(resonpes.data.status == 401){
			file.status = 'noPermission'
		}else {
			file.status = 'fail'
		}
		return file
	}
}
